FAQs - I
Answer: A process is a program that is currently in execution. It consists of the program code, data, CPU registers, program counter, stack, and other resources required for execution.
Answer: A Process Control Block (PCB) contains information required by the operating system to manage a process, such as:
Answer: Process scheduling is the mechanism used by an operating system to select a process from the ready queue and allocate the CPU to it. The scheduler determines which process should run next according to a scheduling algorithm such as FCFS, SJF, Priority, or Round Robin.
Answer: A semaphore is a synchronization variable used to control access to shared resources by multiple processes or threads. It is normally accessed through two atomic operations:
Answer: Paging is a memory-management technique in which a process's logical memory is divided into fixed-size pages, while physical memory is divided into fixed-size frames. A page can be loaded into any available frame, allowing non-contiguous allocation of memory.
Answer: A bit vector is a sequence of bits used to represent the allocation status of resources, particularly free and allocated disk blocks.
For example:
1 0 0 1 1 0
If 1 represents an allocated block and 0 represents a free block, blocks 2, 3, and 6 are free.
Answer: Decryption is the process of converting encrypted or ciphertext data back into its original readable form, called plaintext, using a decryption key.
Answer: I/O optimization refers to techniques used to improve the efficiency and performance of input/output operations. Examples include:
Answer: Inter-Process Communication (IPC) allows processes to exchange data and synchronize their activities. Advantages include:
Answer: A process can be created by an existing process using an operating-system system call. The general process is:
Uses of FORK and JOIN System Calls:
fork() creates a new child process from an existing parent process.
The child process initially receives a copy of the parent's execution context.
Use: Creating a new process.
JOIN: join() is used in process synchronization. It allows a parent process to wait for the completion of a child process or related process. Use: Synchronizing parent and child processes.
| Process | Thread |
|---|---|
| A program in execution | A unit of execution within a process |
| Has its own address space | Shares address space with other threads of the process |
| Creation is relatively expensive | Creation is relatively inexpensive |
| Context Switching is comparatively expensive | Context switching is generally faster |
| Processes communicate using IPS | Threads can communicate through shared memory |
| More isolated | Less isolated |
Answer: Process scheduling determines which ready process receives the CPU and when. Its major roles are:
| Voluntary CPU Sharing | Involuntary CPU sharing |
|---|---|
| A process gives up the CPU voluntarily | OS forcibly takes the CPU from a process |
| Occurs when a process blocks or terminates | Occurs through preemption |
| Common in non-preemptive scheduling | Common in preemptive scheduling |
| Example: process waits for I/O | Example: timer interrupt causes context switch |
Context switching is the process of saving the CPU state of the currently running process and loading the saved state of another process. The saved information may include:
Round Robin: Each process receives a fixed time interval called a time quantum. Example: Processes: P1, P2, P3 Time quantum = 2 ms P1 -> P2 -> P3 -> P1 -> P2 -> ... When a process's quantum expires, it is preempted. Shortest Remaining Time First (SRTF) SRTF is the preemptive version of Shortest Job First. The process having the shortest remaining CPU burst time is selected. If a newly arrived process has a shorter remaining time than the currently running process, the current process is preempted. Preemptive Priority Scheduling Each process is assigned a priority. The process with the highest priority gets the CPU. If a higher-priority process arrives, the currently running process may be preempted. Example:
| Process | Priority |
|---|---|
| P1 | 3 |
| P2 | 1 |
| P3 | 2 |
Mutual exclusion is a synchronization mechanism that ensures that only one process or thread at a time can enter a critical section accessing a shared resource. For example, if two processes modify the same bank account simultaneously, mutual exclusion prevents inconsistent results.
A race condition occurs when multiple processes or threads access shared data concurrently and the final result depends on the order in which their operations execute.
Peterson's Solution
Peterson's algorithm is a software-based solution for achieving mutual exclusion between two processes.
It uses two variables:
flag[2] — indicates whether a process wants to enter the critical section.
turn — indicates which process should get priority.
Conceptually:
flag[i] = true;
turn = j;
while (flag[j] && turn == j)
wait;
Critical Section
flag[i] = false;
Remainder Section
Peterson's solution provides: